/*
 * common.h
 *
 *  Created on: Nov 5, 2016
 *      Author: root
 */

#ifndef COMMON_H_
#define COMMON_H_

#include "../ds/datastructure.h"
#include "../fa/automata.h"
#include "../lex/lexer.h"
#include "../log/logfile.h"

#include "scanner.h"
#include "parser.h"
#include "matcher.h"
#include "sys.h"
#include "macro.h"
#include "refactor.h"
#include "init.h"

#define MACRO_DEF_TEMPLATE    "deftpl"
#define MACRO_DEF_VARIABLE    "defvar"
#define MACRO_DEF_FUNCTION    "defun"
#define MACRO_LAMBDA          "lambda"
#define MACRO_DEF_MACRO       "defmacro"
#define MACRO_DUMP_CODE       "dumpcode"
#define MACRO_DUMP_CLASS      "dumpclass"
#define MACRO_DUMP_HIERARCHY  "dumphierarchy"
#define MACRO_REDEF_FUNCTION  "redefun"
#define MACRO_ADD_METHOD      "addmethod"
#define MACRO_DEF_METHOD      "defmethod"
#define MACRO_REDEF_METHOD    "redefmethod"
#define MACRO_LOAD_TEMPLATE   "loadtpl"
#define MACRO_LOAD_FILE       "loadfile"
#define MACRO_LOAD_PACKAGE    "loadpkg"

#define FILE_TYPE_TEMPLATE 1
#define FILE_TYPE_FILE     2
#define FILE_TYPE_PACKAGE  3

typedef char * (*MacroFunc1)(struct _Statement *);
typedef char * (*MacroFunc2)(struct _Statement *, struct _Statement *);
typedef char * (*MacroFunc3)(struct _Statement *, struct _Statement *, struct _Statement *);
typedef char * (*MacroFunc4)(struct _Statement *, struct _Statement *, struct _Statement *, struct _Statement *);

Map *macros;
void init_macro_functions();
void *get_macro_function(String name);
String macro_function(String functionName, int argc, Statement **argv);

String rule(Statement *s1, Statement *s2);
String group(Statement *s1, Statement *s2);
String token(Statement *s1, Statement *s2);
String lex(Statement *s);

String extract(Statement *s);
String arglist(Statement *s);
String target(Statement *s);
String funcname(Statement *s);

String signature(Statement *s);
String symname(Statement *s);

String loadtemplate(Statement *s);
String loadfile(Statement *s);
String loadpackage(Statement *s);

#endif /* COMMON_H_ */
